package com.dsbj.mp.icardservice.utils;

import com.alibaba.fastjson.JSONObject;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by ace on 2017/9/10.
 */
public class StringHelper {
	public static String getObjectValue(Object obj) {
		return obj == null ? "" : obj.toString();
	}
	
	/**
	 * 以JSON格式输出
	 *
	 * @param response
	 */
	public static void renderResponse(HttpServletResponse response, Object responseObject) {
		//将实体对象转换为JSON Object转换
		String jsonStr = JSONObject.toJSONString(responseObject);
		response.setCharacterEncoding("UTF-8");
		response.setContentType("application/json; charset=utf-8");
		PrintWriter out = null;
		try {
			out = response.getWriter();
			out.append(jsonStr);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (out != null) {
				out.close();
			}
		}
	}
	
	
	
}
